﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Core.GenericDefinitions.BaseClasses;
using Core.Helpers.CommonHelpers;
using Core.Requests.SRVUICommonRequests;
using Core.GenericDefinitions.Enums;

namespace Service.EOrgService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class EOrgService : IEOrgService
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }

        public byte[] DoWork(byte[] incommingBytes)
        {
            RequestBase rb = (RequestBase)Converter.CompressedByteArrayToObject(incommingBytes);
            ResponseBase response = new ResponseBase();
            //#region LoginControl
            //Core.DataBaseAccess.EOrgDataClassesDataContext dc = new Core.DataBaseAccess.EOrgDataClassesDataContext();
            //byte? userExists = 0;
            //dc.kup_LoginControl(rb.LoginInfo.UserName, rb.LoginInfo.Password, ref userExists);
            //if (userExists == 0)
            //{
            //    response.Error = Errors.LoginFailed;
            //    response.Message = "Login Failed For User " + rb.LoginInfo.UserName;
            //    return Converter.ObjectToCommpressedByteArray(response);
            //}
            //#endregion

            response = rb.Process();
            return Converter.ObjectToCommpressedByteArray(response);
        }
    }
}
